home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Toolbox
/
Visual Basic Toolbox (P.I.E.)(1996).ISO
/
dde
/
odbcncap
/
module1.bas
< prev
next >
Wrap
BASIC Source File
|
1995-10-26
|
4KB
|
110 lines
Sub ODBCBuildParams (parmCDataType As Integer, parmSQLDataType As Integer, parmVariableValue As Variant, parmPrecision As Integer, parmScale As Integer, inIndex As Integer)
If inIndex > 1 Then
ReDim Preserve aParmList(inIndex)
Else
If inIndex = 0 Then
ReDim aParmList(inIndex)
Exit Sub
Else
ReDim aParmList(inIndex)
End If
End If
aParmList(inIndex).nCDataType = parmCDataType
aParmList(inIndex).nSQLDataType = parmSQLDataType
aParmList(inIndex).vVariableValue = parmVariableValue
aParmList(inIndex).nPrecision = parmPrecision
aParmList(inIndex).nScale = parmScale
End Sub
Function ODBCExecute (hDbc As Long, hStmt As Long, sSourceSQL As String, ParmArray() As ODBCArrayType) As Integer
Dim nStatus As Integer
Dim i As Integer
Dim workString() As String
Dim workLongInteger() As Long
Dim workInteger() As Integer
Dim workSingle() As Single
Dim workDouble() As Double
'
' Hope for the best!
'
ODBCExecute = True
If UBound(ParmArray) <> 0 Then
For i = 1 To UBound(ParmArray, 1)
Select Case VarType(ParmArray(i).vVariableValue)
Case V_STRING
ReDim Preserve workString(i)
workString(i) = ParmArray(i).vVariableValue
Case V_LONG
ReDim Preserve workLongInteger(i)
workLongInteger(i) = ParmArray(i).vVariableValue
Case V_INTEGER
ReDim Preserve workInteger(i)
workInteger(i) = ParmArray(i).vVariableValue
Case V_DOUBLE
ReDim Preserve workDouble(i)
workDouble(i) = ParmArray(i).vVariableValue
Case V_SINGLE
ReDim Preserve workSingle(i)
workSingle(i) = ParmArray(i).vVariableValue
Case V_DATE
workString(i) = Format(ParmArray(i).vVariableValue, "Short Date")
Case Else
MsgBox "Invalid value for a parameter"
ODBCExecute = False
GoTo ODBCExecute_Continue
End Select
Select Case ParmArray(i).nCDataType
Case SQL_C_CHAR
' Applies to VB strings going to char, varchar and text datatypes.
nStatus = SQLSetParam(hStmt, i, ParmArray(i).nCDataType, ParmArray(i).nSQLDataType, ParmArray(i).nPrecision, ParmArray(i).nScale, ByVal workString(i), SQL_NTS)
Case Else
' Applies to VB long going to integer datatype
Select Case VarType(ParmArray(i).vVariableValue)
Case V_LONG
nStatus = SQLSetParam(hStmt, i, ParmArray(i).nCDataType, ParmArray(i).nSQLDataType, ParmArray(i).nPrecision, ParmArray(i).nScale, workLongInteger(i), SQL_NTS)
Case V_INTEGER
nStatus = SQLSetParam(hStmt, i, ParmArray(i).nCDataType, ParmArray(i).nSQLDataType, ParmArray(i).nPrecision, ParmArray(i).nScale, workInteger(i), SQL_NTS)
Case V_DOUBLE
nStatus = SQLSetParam(hStmt, i, ParmArray(i).nCDataType, ParmArray(i).nSQLDataType, ParmArray(i).nPrecision, ParmArray(i).nScale, workDouble(i), SQL_NTS)
Case V_SINGLE
nStatus = SQLSetParam(hStmt, i, ParmArray(i).nCDataType, ParmArray(i).nSQLDataType, ParmArray(i).nPrecision, ParmArray(i).nScale, workSingle(i), SQL_NTS)
Case Else
MsgBox "Invalid value for a parameter"
ODBCExecute = False
GoTo ODBCExecute_Continue
End Select
End Select
If nStatus = SQL_SUCCESS Then
'
' Continue...
'
Else
If nStatus <> SQL_SUCCESS_WITH_INFO Then
DescribeError hDbc, hStmt
ODBCExecute = False
GoTo ODBCExecute_Continue
End If
End If
Next i
End If
nStatus = SQLExecDirect(hStmt, sSourceSQL, Len(sSourceSQL))
If nStatus <> SQL_SUCCESS Then '*** SQL Success = 0
DescribeError hDbc, hStmt
ODBCExecute = False
End If
ODBCExecute_Continue:
Exit Function
End Function